package com.buaa.aimall.Utils;

import com.alibaba.fastjson.annotation.JSONField;
import com.buaa.aimall.Utils.Enum.StatusCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class BaseResponse<T> {
    @JSONField(serializeUsing = StatusCodeSerializer.class)
    private StatusCode code;

    private String msg;

    private T data;

    public BaseResponse(String messgePrefix, Boolean result, T data) {
        this.msg = result ? messgePrefix + "成功" : messgePrefix + "失败";
        this.code = result ? StatusCode.SUCCESS : StatusCode.DAO_ERROR;
        this.data = data;
    }

    public BaseResponse(String successMessage, String errorMessage, Boolean result, T data) {
        this.msg = result ? successMessage : errorMessage;
        this.code = result ? StatusCode.SUCCESS : StatusCode.DAO_ERROR;
        this.data = data;
    }
}
